<template>
  <div class="invite-bg">
    <title-bar title="加入申请" :gobackshow=false></title-bar>
    <div class="invite">
      <div class="invite-member">
        <img class="invite-member-pic" :src=" avatarurl || defaulturl" alt="头像">
        <span class="invite-member-text">{{ nickname }}</span>
        <span class="invite-member-subtext">  申请加入</span>
      </div>
      <div class="invite-activity">
        <div class="invite-activity-id">活动ID: {{ activityid }}</div>
        <div class="invite-activity-info">
          <div class="invite-activity-info-text">{{ content }}</div>
          <img class="invite-activity-info-pic" :src=" images[0].url " alt="活动照片" v-if="images[0].url">
        </div>
      </div>

      <div class="invite-buttons" v-if="buttonStatus">
        <button class="invite-button" @click="reject">拒绝</button>
        <button class="invite-button" @click="agree">同意</button>
      </div>
      <div class="invite-text" v-else>
        <div class="invite-text-subtext">已同意</div>
      </div>
    </div>
  </div>
</template>

<script>
import {PostServiceClass} from '../../services/post.js';
import {PostMemberService} from '../../services/postmember.js';
import {DEFAULT_AVATAR} from "../../const"
import {BusinessException} from "../../request"

const AvtiveForUser = {
    Normal: 0,
    Joining: 1,
    Joined: 2,
    Master: 3
}

export default {
  components: {},
  route:{
    data({ to: { params: { postId } }}){
        this.id = postId
        this.getItem()
    }
  },
  data: function(){
    return {
      defaulturl: DEFAULT_AVATAR,
      activityid: '',
      nickname: '',
      avatarurl: '',
      content: '',
      images: [],
      activeForUser: 0,
    }
  },
  computed:{
    buttonStatus: function(){
      return this.activeForUser === AvtiveForUser.Normal
    }
  },
  methods: {
    async getItem(){
      await this.service.GetAsync(this.id)
        .then(({ authorNickName, authorAvatarUrl, id, content, images ,current})=>{
          this.nickname = authorNickName;
          this.avatarurl = authorAvatarUrl;
          this.activityid = id;
          this.content = content;
          this.images = images;
          this.activeForUser = current.avtiveForUser;
        })
    },
    reject(){

    },
    agree(){
        this.postMemberService.Join({
          id: this.id,
          nickName: this.remarkName,
          reamark:this.remarkInfo,
          invitationCode: this.$route.query.invitationCode
        }).then((res) => {
          window.location.reload()
        })
    }
  },
  init() {
    this.postMemberService = new PostMemberService()
    this.service = new PostServiceClass
  }
}
</script>

<style lang='sass'>
    @import '../../vendor/styles/invite.scss';
</style>










